package univ.uchiha.esiag.gon.broadcaster;

import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.Socket;

public class BroadcasterRemote extends Thread{
	private String ior;
	public BroadcasterRemote(String ior) {
		this.ior = ior;
	}
	@Override
	public void run() {
		try{
			MulticastSocket socket = new MulticastSocket(8090);
			socket.joinGroup(InetAddress.getByName("228.5.6.7"));
			while(true){
				byte[] buf = new byte[1000];
				DatagramPacket packet = new DatagramPacket(buf, buf.length);
				socket.receive(packet);
				
				Socket socket1 = new Socket(packet.getAddress(), 8091);
				PrintWriter pw = new PrintWriter(socket1.getOutputStream());
				pw.print(ior);
				pw.flush();
				pw.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
